package lium.lbs.lbsim.activity

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.buz.hjcdriver.bean.EstablishQunBean
import com.lmlibrary.bean.ResponseBean
import com.lzy.okgo.model.Response
import kotlinx.android.synthetic.main.activity_ingroup_by_money.*
import lium.lbs.lbsim.R
import lium.lbs.lbsim.jgchat.application.GJApp
import lium.lbs.lbsim.pay.ChoosePayWayActivity
import lium.lbs.lbsim.utils.ToastUtils
import lium.lbs.lbsim.utils.callbck.DialogCallback
import java.util.HashMap

class InGroupByMoneyActivity : BaseActivity() {


    var groupId: String? = null
    var applyId: String? = null
    var orderSn: String? = null
    var price: String? = null
    var groupName: String? = null

    override fun getLayoutId(): Int {
        return R.layout.activity_ingroup_by_money
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitleWithBack("申请加群")
        addOnClickListeners(
            R.id.btn_pay
        )
        groupId = intent.getStringExtra(GJApp.MY_GROUP_ID)
        applyId = intent.getStringExtra("applyId")
        orderSn = intent.getStringExtra("orderSn")
        price = intent.getStringExtra("price")
        groupName = intent.getStringExtra("groupName")

        topay_money.text = "￥" + price
        topay_groupName.text = groupName
    }


    override fun onClick(v: View?) {
        super.onClick(v)
        when (v!!.id) {
            R.id.btn_pay -> {
                intent.setClass(this, ChoosePayWayActivity::class.java)
                intent.putExtra("orderSN", orderSn)
                intent.putExtra("moeny", price)
                intent.putExtra("type", 1)
                intent.putExtra("name", "入群付款")
                startActivityForResult(intent, 100)
            }
        }
    }

    fun getDataList() {
        val param = HashMap<String, String>()
        postData(
            "/group/getCreateGroupMoney",
            param,
            object : DialogCallback<ResponseBean<EstablishQunBean>>(this) {
                override fun onSuccess(response: Response<ResponseBean<EstablishQunBean>>) {
                    setDataList(response.body().data)
                }
            })
    }

    fun setDataList(establishQunBean: EstablishQunBean) {
        pay_rule.text = establishQunBean?.joinContent
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 100 && resultCode == 200) {
            setResult(200)
            finish()
        }
    }

    fun setDataList(msg: String) {
        ToastUtils.showLongToast(msg)
        finish()
    }


    override fun getNetWorkData() {

    }
}
